<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

	/**
	 * Log initalization
	 */
	protected function _initLog() {
		if ($this->hasPluginResource("Log")) {
			$r = $this->getPluginResource("Log");
			$log = $r->getLog();
			$format = "%timestamp% %priorityName% %message%" . PHP_EOL;
			$formattter = new Zend_Log_Formatter_Simple($format);
			Zend_Registry::set('log', $log);
		}
	}

	/**
	 * Lets using ZFDebug using front controller
	 */
	protected function _initZFDebug() {
		//$autoloader = Zend_Loader_Autoloader::getInstance();
		//$autoloader->registerNamespace('ZFDebug');

		$options = array(
		'jquery_path' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js',
        'plugins' => array('Variables',
							'Html',
                           'File' => array('basePath' => APPLICATION_PATH . '/../'),
							'Database' => array(),
                           'Memory', 
                           'Time', 
		//'Registry',
                           'Log',
                           'Exception')
		);
		$debug = new ZFDebug_Controller_Plugin_Debug($options);

		$this->bootstrap('frontController');
		$frontController = $this->getResource('frontController');
		$frontController->registerPlugin($debug);

	}

	protected function _initConfig() {
		/*
		 $aConfig    = $this->getOptions();
		 Zend_Registry::set('wssg_client_id', $aConfig['wssg']['client_id']);
		 Zend_Registry::set('wssg_client_secret', $aConfig['wssg']['client_secret']);
		 Zend_Registry::set('wssg_redirect_uri', $aConfig['wssg']['redirect_uri']);
		 // Used for both Code & Access Flow
		 Zend_Registry::set('wssg_authorize_uri', $aConfig['wssg']['authorize_uri']);
		 // Used for Mobile Flow
		 Zend_Registry::set('wssg_token_uri',  $aConfig['wssg']['token_uri']);
		 // Used for Code flow
		 Zend_Registry::set('wssg_code_to_accesstoken_uri', $aConfig['wssg']['code_to_accesstoken_uri']);
		 */
	}



	/**
	 * Session initation wil happen over here
	 * Loads the session configuration file opts and starts the session
	 */
	protected function _initSession() {

		$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/session.ini', APPLICATION_ENV);
		Zend_Session::setOptions($config->toArray());
		Zend_Session::start();

	}

	/**
	 * point the location of configuration required for Macys
	 * Sets the Zend_Config array to registry
	 */
	protected function _initProtectedServices() {
		$wssgConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/protectedservices.ini', APPLICATION_ENV);
		$mreg = new Zend_Registry();
		$mreg->set('Macys', $wssgConfig->toArray());
	}

	protected function _initPublicServices() {
		$wssgConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/publicservices.ini', APPLICATION_ENV);
		$mreg = new Zend_Registry();
		$mreg->set('Macys_Public', $wssgConfig->toArray());
	}
	
	protected function _initConfigLoad() {
		$conf = new Zend_Config_Ini(APPLICATION_PATH . '/configs/wssgservices.ini', APPLICATION_ENV);
		$regIns = new Zend_Registry();
		$regIns->set('MACYS_CONFIG', $conf->toArray());
	}

	/**
	 * used for handling top-level navigation
	 * @return Zend_Navigation
	 */
	protected function _initNavigation()
	{

		$this->bootstrap('layout');
		$this->bootstrap('view');
		$layout = $this->getResource('layout');
		$view = $layout->getView();
		$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
		$container = new Zend_Navigation($config);
		$view->navigation($container);
			
	}

	protected function _initMyActionHelpers()
	{

		/*

		$signup = Zend_Controller_Action_HelperBroker::getStaticHelper('Signup');
		$simpleTest = Zend_Controller_Action_HelperBroker::getStaticHelper('SimpleTest');
		Zend_Controller_Action_HelperBroker::addHelper($signup);
		Zend_Controller_Action_HelperBroker::addHelper($simpleTest);
		*/
	}

	protected function _initCategoryNavigationPlugin()
	{
		// TODO Remove this
		$this->bootstrap("frontController");
		$this->frontController->registerPlugin(new Macys_Controllers_SidePanel_Category);

	}
}

